package com.yxh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yxh.base.PageEntity;
import com.yxh.dao.HistoryMapper;
import com.yxh.dao.ViciousMapper;
import com.yxh.pojo.History;
import com.yxh.pojo.Vicious;
import com.yxh.service.FlowManageService;
import com.yxh.service.ViciousService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by asus on 2018/6/5.
 */

@Service
@Transactional
public class ViciousServiceImpl implements ViciousService {

    @Autowired
    private ViciousMapper viciousMapper;

    @Autowired
    private HistoryMapper historyMapper;

    @Autowired
    private FlowManageService flowManageService;

    @Override
    public int save(Vicious record) {

        try {
            return viciousMapper.insertSelective(record);
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }

    }

    @Override
    public int update(Vicious record) {
        try {
            return  viciousMapper.updateByPrimaryKeySelective(record);
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public int delete(String id) {
        return 0;
    }

    @Override
    public void batchDelete(List<Vicious> records) {

    }

    @Override
    public Vicious get(String id) {
        return null;
    }

    @Override
    public Vicious get(Vicious record) {
        return null;
    }

    @Override
    public List<Vicious> getList(Vicious record) {
        return null;
    }

    @Override
    public List<Vicious> getAllList(Vicious record) {
        return null;
    }

    @Override
    public List<Vicious> getListPage(PageEntity<Vicious> record) {
        return null;
    }

    @Override
    public PageInfo getInformation(Vicious record, Integer page, Integer pageSize) {

        PageHelper.startPage(page, pageSize);
        List<Map<String,Object>> menuList =viciousMapper.selectByVicious(record);
        PageInfo pageInfo = new PageInfo(menuList);
        pageInfo.setList(menuList);
        return pageInfo;
    }

    @Override
    public int insertImg(Map<String, Object> parm) {
        try {
            return viciousMapper.insertImg(parm);
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public Map<String, Object> get1(String id) {
        Map<String, Object> m=viciousMapper.selectByPrimaryKey(id);
        if(m==null){
            return m;
        }
        List<Map<String, Object>> li=viciousMapper.getListImgs(id);
        if(li.size()!=0){
            m.put("imgs",li);
        }

        if(m!=null&&m.get("auditingId")!=null)
            m.put("auditingName", flowManageService.nameBack(m.get("auditingId").toString()));

        return m;
    }

    @Override
    public int insertHistroy(History h) {
        try {
            return historyMapper.insertSelective(h);
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }
}
